import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation;
import 'package:flutter_gallery/data/gallery_options.dart';
import 'package:flutter_gallery/studies/crane/app.dart';
import 'package:flutter_gallery/studies/fortnightly/app.dart';
import 'package:flutter_gallery/studies/rally/app.dart';
import 'package:flutter_gallery/studies/starter/app.dart';
import 'package:flutter_gallery/themes/gallery_theme_data.dart';
import 'package:flutter_gallery/constants.dart';
import 'package:flutter_gen/gen_l10n/gallery_localizations.dart';
import 'package:flutter_localized_locales/flutter_localized_locales.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  final bool isTestMode;
  final String? initialRoute;

  const MyApp({
    Key? key,
    this.initialRoute,
    this.isTestMode = false,
  }) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ModelBinding(
        initialModel: GalleryOptions(
          themeMode: ThemeMode.system,
          textScaleFactor: systemTextScaleFactorOption,
          customTextDirection: CustomTextDirection.localeBased,
          timeDilation: timeDilation,
          platform: defaultTargetPlatform,
          isTestMode: isTestMode,
        ),
        child: Builder(
          builder: (context) {
            return MaterialApp(
              scrollBehavior:
                  const MaterialScrollBehavior().copyWith(scrollbars: false),
              restorationScopeId: 'rootGallery',
              title: 'Flutter Gallery',
              debugShowCheckedModeBanner: false,
              themeMode: GalleryOptions.of(context).themeMode,
              theme: GalleryThemeData.lightThemeData.copyWith(
                platform: GalleryOptions.of(context).platform,
              ),
              darkTheme: GalleryThemeData.darkThemeData.copyWith(
                platform: GalleryOptions.of(context).platform,
              ),
              localizationsDelegates: const [
                ...GalleryLocalizations.localizationsDelegates,
                LocaleNamesLocalizationsDelegate()
              ],
              supportedLocales: GalleryLocalizations.supportedLocales,
              locale: GalleryOptions.of(context).locale,
              localeListResolutionCallback: (locales, supportedLocales) {
                return basicLocaleListResolution(locales, supportedLocales);
              },
              // home: const AppBarDemo(),
              // home: const BannerDemo(),
              // home: const BottomAppBarDemo(),
              // home: const BottomNavigationDemo(
              //   type: BottomNavigationDemoType.withLabels,
              //   restorationId: 'bottom_navigation_labels_demo',
              // ),
              // home: const BottomSheetDemo(type: BottomSheetDemoType.modal),
              // home: const ButtonDemo(type: ButtonDemoType.toggle),
              // home: const CardsDemo(),
              // home: const ChipDemo(type: ChipDemoType.input),
              // home: const DataTableDemo(),
              // home: const DialogDemo(type: DialogDemoType.alertTitle),
              // home: const DividerDemo(type: DividerDemoType.horizontal),
              // home: const GridListDemo(type: GridListDemoType.footer),
              // home: const ListDemo(type: ListDemoType.twoLine),
              // home: const MenuDemo(type: MenuDemoType.checklistMenu),
              // home: const NavDrawerDemo(),
              // home: const NavRailDemo(),
              // home: const PickerDemo(type: PickerDemoType.range),
              // home: const ProgressIndicatorDemo(type: ProgressIndicatorDemoType.linear),
              // home: const SelectionControlsDemo(type: SelectionControlsDemoType.switches),
              // home: const SlidersDemo(type: SlidersDemoType.customSliders),
              // home: const SnackbarsDemo(),
              // home: const TabsDemo(type: TabsDemoType.scrollable),
              // home: const TextFieldDemo(),
              // home: const TooltipDemo(),
              // home: const ColorsDemo(),
              // home: const OpenContainerTransformDemo(),
              // home: const FadeScaleTransitionDemo(),
              // home: const FadeThroughTransitionDemo(),
              // home: const SharedXAxisTransitionDemo(),
              // home: const SharedYAxisTransitionDemo(),
              // home: const SharedZAxisTransitionDemo(),
              // home: const TransformationsDemo(),
              // home: const TypographyDemo(),
              // home: const StarterApp(),
              // home: const FortnightlyApp(),
              // home: const CraneApp(),
              home: const RallyApp(),
            );
          },
        ));
  }
}
